package thread;

public class demo11 {
    public static void moveZeroes(int[] nums) {
        int left = 0;
        int right = 0;
        // 遍历数组
        while (right < nums.length) {
            // 如果当前元素非0，则将其与left指向的元素交换位置，同时left和right都后移
            if (nums[right]!= 0) {
                int temp = nums[left];
                nums[left] = nums[right];
                nums[right] = temp;
                left++;
            }
            right++;
        }
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3,4,0,6};
        moveZeroes(nums);
        for (int num : nums) {
            System.out.print(num + " ");
        }
    }
}
